import axios from 'axios'

axios.defaults.baseURL = 'http://localhost:8888/api/private/v1'

// 添加axios拦截器,为每一个请求都添加一个一个token:
axios.interceptors.request.use(function (config) {
  // 先从本地获取到token:
  let mytoken = localStorage.getItem('mytoken')
  // 如果token存在,则把他放进去:
  if (mytoken) {
    config.headers.Authorization = mytoken
  }
  // 请求需要发送回去
  return config
}, function (error) {
  return Promise.reject(error)
}
)

export const login = obj => axios.post('/login', obj).then(res => res.data)

// 获取菜单权限
export const getMenus = () => axios.get('/menus').then(res => res.data)
